package org.unisinos.gc.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.unisinos.gc.dao.AreaDAO;
import org.unisinos.gc.dao.SubAreaDAO;
import org.unisinos.gc.form.SubAreaForm;
import org.unisinos.gc.vo.SubArea;

public class GetSubAreaDetailAction extends Action {
	
	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		super.execute(mapping, form, request, response);

		String codigo = (String)request.getParameter("codigo");
		
		SubAreaForm subareaForm = (SubAreaForm)form;
		if (StringUtils.isNumeric(codigo)) {
			SubArea subarea = SubAreaDAO.getSubArea(Integer.parseInt(codigo));
			subareaForm.parseSubArea(subarea);
			request.setAttribute("mode", "edit");
		}else {
			request.setAttribute("mode", "new");
		}
		
		request.setAttribute("areaList", AreaDAO.getAreaList());
		return mapping.findForward("success");
	}

}
